package chat

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"shangyuapi/data_source"
	"shangyuapi/models"
	"time"
	"unicode/utf16"
)

func Shandonguser(ctx *gin.Context) {
	start, end := getWeekStartAndEnd()

	var shandongs []models.Shandong
	data_source.Db.Where("addtime >= ?", start).Where("addtime < ?", end).Find(&shandongs)
	var uidarr []int64
	for _, v := range shandongs {
		uidarr = append(uidarr, v.Uid)
	}
	var users []models.User
	data_source.Db.Where("uid")
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    users,
		"msg":     "ok",
	})
	return
}
func getWeekStartAndEnd() (startTime, endTime int64) {
	// 获取当前时间
	now := time.Now()

	// 获取本周的第一天（周日）
	startOfWeek := now.AddDate(0, 0, -int(now.Weekday()))
	startTime = startOfWeek.Unix()

	// 本周的最后一天（周六）
	endOfWeek := startOfWeek.AddDate(0, 0, 6)
	endTime = endOfWeek.Unix()

	return
}

// EmojiEncode Emoji表情转码
func EmojiEncode(s string) string {
	ret := ""
	rs := []rune(s)
	for i := 0; i < len(rs); i++ {
		if len(string(rs[i])) == 4 {
			r1, r2 := utf16.EncodeRune(rs[i])
			t1 := "\\u" + fmt.Sprintf("%x", r1)
			t2 := "\\u" + fmt.Sprintf("%x", r2)
			ret += t1 + t2
		} else {
			ret += string(rs[i])
		}
	}
	return ret
}
